<?php

class UserController extends Controller
{
	public function index()
	{
		$data = DB::table('user')->order('id desc')->select();
        $this->assign('title','用户列表');
        $this->assign('list', $data);
        $this->display('./User/index.html');
	}
	
    public function del()
    {
        DB::table('user')->delete($_GET['id']);
        $m = DB::table('user')->order('id desc')->select();
        echo json_encode($m);
    }

    public function add()
    {
        $this->assign('title', '用户添加页面');
        $this->display('./User/add.html');
    }

    public function insert()
    {
        if (DB::table('user')->insert() > 0) {
            $this->redirect('添加成功', URL.'User/index');
        } else {
            $this->redirect('添加失败');
        }
    }

    public function edit()
    {
        $data = DB::table('user')->find($_GET['id']);
        $this->assign('title', '用户编辑页面');
        $this->assign('data', $data);
        $this->display('./User/edit.html');
    }

    public function update()
    {
        if (DB::table('user')->update()) {
            $this->redirect('编辑成功', URL.'User/index');
        } else {
            $this->redirect('编辑失败');
        }
    }

}